/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package telas;

import Funcoes.Funcao;
import classes.Cliente;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.swing.JOptionPane;

/**
 *
 * @author sabrina
 */
public class cadastroCliente extends javax.swing.JInternalFrame {

    EntityManager gerenciador;
    Query consulta;
    Cliente cliente = new Cliente();

    /**
     * Creates new form cadastroCliente
     */
    public cadastroCliente() {
        
        initComponents();
        
        this.reiniciaFormulario();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btn_novo = new javax.swing.JButton();
        painel_cad = new javax.swing.JPanel();
        cli_lbl1 = new javax.swing.JLabel();
        cli_lbl2 = new javax.swing.JLabel();
        cli_lbl3 = new javax.swing.JLabel();
        cli_lbl4 = new javax.swing.JLabel();
        txt_nome = new javax.swing.JTextField();
        txt_email = new javax.swing.JTextField();
        txt_cpf = new javax.swing.JFormattedTextField();
        txt_tel = new javax.swing.JFormattedTextField();
        lbl_cod = new javax.swing.JLabel();
        lbl_codigo_cli = new javax.swing.JLabel();
        painel_cad2 = new javax.swing.JPanel();
        cli_lbl5 = new javax.swing.JLabel();
        btn_buscar_cli = new javax.swing.JButton();
        txt_busca = new javax.swing.JFormattedTextField();
        btn_anterior = new javax.swing.JButton();
        btn_proximo = new javax.swing.JButton();
        btn_limpar = new javax.swing.JButton();
        btn_cancela = new javax.swing.JButton();
        btn_salvar = new javax.swing.JButton();
        btn_alterar = new javax.swing.JButton();

        setBorder(null);
        setClosable(true);
        setTitle("Cadastro de Cliente");
        setPreferredSize(new java.awt.Dimension(520, 400));

        btn_novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botao_novo.png"))); // NOI18N
        btn_novo.setText(" Novo");
        btn_novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_novoActionPerformed(evt);
            }
        });

        painel_cad.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        cli_lbl1.setText("Nome:");

        cli_lbl2.setText("CPF:");

        cli_lbl3.setText("Telefone:");

        cli_lbl4.setText("E-mail:");

        txt_email.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_emailActionPerformed(evt);
            }
        });

        try {
            txt_cpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            txt_tel.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)#####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        lbl_cod.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbl_cod.setText("Cod Cliente:");

        lbl_codigo_cli.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbl_codigo_cli.setForeground(new java.awt.Color(255, 0, 0));
        lbl_codigo_cli.setToolTipText("codigo do equipamento");

        javax.swing.GroupLayout painel_cadLayout = new javax.swing.GroupLayout(painel_cad);
        painel_cad.setLayout(painel_cadLayout);
        painel_cadLayout.setHorizontalGroup(
            painel_cadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_cadLayout.createSequentialGroup()
                .addGroup(painel_cadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painel_cadLayout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addComponent(lbl_cod)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbl_codigo_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(painel_cadLayout.createSequentialGroup()
                        .addGroup(painel_cadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(painel_cadLayout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addGroup(painel_cadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cli_lbl3)
                                    .addComponent(cli_lbl4)
                                    .addComponent(cli_lbl2)))
                            .addGroup(painel_cadLayout.createSequentialGroup()
                                .addGap(46, 46, 46)
                                .addComponent(cli_lbl1)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(painel_cadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txt_email, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txt_cpf, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txt_tel, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(110, Short.MAX_VALUE))
        );
        painel_cadLayout.setVerticalGroup(
            painel_cadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_cadLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painel_cadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbl_cod, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl_codigo_cli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(painel_cadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cli_lbl1))
                .addGap(18, 18, 18)
                .addGroup(painel_cadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cli_lbl2)
                    .addComponent(txt_cpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(painel_cadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cli_lbl3)
                    .addComponent(txt_tel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(painel_cadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cli_lbl4)
                    .addComponent(txt_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(65, 65, 65))
        );

        painel_cad2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        cli_lbl5.setText("CPF :");

        btn_buscar_cli.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botao_procurar.png"))); // NOI18N
        btn_buscar_cli.setText("Buscar");
        btn_buscar_cli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_buscar_cliActionPerformed(evt);
            }
        });

        try {
            txt_busca.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        btn_anterior.setText("Anterior");
        btn_anterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_anteriorActionPerformed(evt);
            }
        });

        btn_proximo.setText("Próximo");
        btn_proximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_proximoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout painel_cad2Layout = new javax.swing.GroupLayout(painel_cad2);
        painel_cad2.setLayout(painel_cad2Layout);
        painel_cad2Layout.setHorizontalGroup(
            painel_cad2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painel_cad2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btn_anterior, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_proximo, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(cli_lbl5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txt_busca, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_buscar_cli)
                .addContainerGap())
        );
        painel_cad2Layout.setVerticalGroup(
            painel_cad2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_cad2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(painel_cad2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cli_lbl5)
                    .addComponent(btn_buscar_cli)
                    .addComponent(txt_busca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_anterior)
                    .addComponent(btn_proximo))
                .addGap(23, 23, 23))
        );

        btn_limpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/stop.png"))); // NOI18N
        btn_limpar.setText("Limpar");
        btn_limpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_limparActionPerformed(evt);
            }
        });

        btn_cancela.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/remove.png"))); // NOI18N
        btn_cancela.setText("Cancelar ");
        btn_cancela.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_cancelaMouseClicked(evt);
            }
        });
        btn_cancela.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_cancelaActionPerformed(evt);
            }
        });

        btn_salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/accept.png"))); // NOI18N
        btn_salvar.setText("Salvar");
        btn_salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_salvarActionPerformed(evt);
            }
        });

        btn_alterar.setText("Alterar");
        btn_alterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_alterarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(painel_cad2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(painel_cad, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btn_novo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_cancela)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_salvar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_limpar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_alterar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_novo)
                    .addComponent(btn_limpar)
                    .addComponent(btn_cancela)
                    .addComponent(btn_salvar)
                    .addComponent(btn_alterar))
                .addGap(21, 21, 21)
                .addComponent(painel_cad2, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22)
                .addComponent(painel_cad, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_salvarActionPerformed
        gerenciador = Funcoes.Funcao.conectar();

        cliente.setCliCpf(this.txt_cpf.getText());
        cliente.setCliNome(this.txt_nome.getText());
        cliente.setCliEmail(this.txt_email.getText());
        cliente.setCliTel(this.txt_tel.getText());

        Funcoes.Funcao.persistir(gerenciador, cliente);
        Funcoes.Funcao.fechar(gerenciador);//fecha conecxão 

        this.txt_cpf.setText("");
        this.txt_nome.setText("");
        this.txt_tel.setText("");
        this.txt_email.setText("");

        this.reiniciaFormulario();

        JOptionPane.showMessageDialog(null, "Cadastro efetuado com sucesso!"); // se salvou retorna ok 

    }//GEN-LAST:event_btn_salvarActionPerformed

    private void txt_emailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_emailActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_emailActionPerformed

    private void btn_cancelaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_cancelaActionPerformed

        this.reiniciaFormulario();

    }//GEN-LAST:event_btn_cancelaActionPerformed

    private void btn_cancelaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_cancelaMouseClicked

    }//GEN-LAST:event_btn_cancelaMouseClicked

    private void btn_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_novoActionPerformed
        txt_nome.setEnabled(true);
        txt_cpf.setEnabled(true);
        txt_tel.setEnabled(true);
        txt_email.setEnabled(true);
        this.txt_busca.setEnabled(false);

        this.btn_buscar_cli.setEnabled(false);
        this.btn_novo.setEnabled(false);
        btn_salvar.setEnabled(true);
        btn_cancela.setEnabled(true);
        btn_limpar.setEnabled(true);       // Ativa Todos os botoes ao clicar
    }//GEN-LAST:event_btn_novoActionPerformed

    private void btn_limparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_limparActionPerformed
        txt_busca.setText(null);
        txt_nome.setText(null);
        txt_cpf.setText(null);
        txt_tel.setText(null);
        txt_email.setText(null);        // Apaga o que já foi digitado
    }//GEN-LAST:event_btn_limparActionPerformed

    private void btn_buscar_cliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_buscar_cliActionPerformed

        gerenciador = Funcao.conectar(); // abre a conexão com o banco 

        consulta = gerenciador.createQuery("select c from Cliente c where c.cliCpf = :cliCpf"); //HQl
        consulta.setParameter("cliCpf", txt_busca.getText());

        cliente = (Cliente) consulta.getSingleResult();

        this.lbl_codigo_cli.setText("" + cliente.getId());
        this.txt_nome.setText(cliente.getCliNome());
        this.txt_cpf.setText(cliente.getCliCpf());
        this.txt_tel.setText(cliente.getCliTel());
        this.txt_email.setText(cliente.getCliEmail());

        this.txt_cpf.setEnabled(true);
        this.txt_email.setEnabled(true);
        this.txt_nome.setEnabled(true);
        this.txt_tel.setEnabled(true);

        this.txt_busca.setText("");
        this.btn_anterior.setEnabled(true);
        this.btn_proximo.setEnabled(true);
        this.btn_cancela.setEnabled(true);
        this.btn_novo.setEnabled(false);
        this.btn_alterar.setEnabled(true);

        Funcao.fechar(gerenciador); // fecha conexão com o banco 
    }//GEN-LAST:event_btn_buscar_cliActionPerformed

    private void btn_anteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_anteriorActionPerformed
        gerenciador = Funcao.conectar();

        try {//TRATAMENTO DE ERROS
            //Seleciona apenas o primeiro registro com o id menor que o passado
            consulta = gerenciador.createQuery("select c from Cliente c where c.id < :id order by c.id desc");//HQL
            consulta.setParameter("id", Integer.parseInt(this.lbl_codigo_cli.getText())); //Compara o id do banco com o id do parâmetro
            consulta.setMaxResults(1);//Captura o primeiro registro
            cliente = (Cliente) consulta.getSingleResult();

            this.lbl_codigo_cli.setText("" + cliente.getId());
            this.txt_nome.setText(cliente.getCliNome());
            this.txt_cpf.setText(cliente.getCliCpf());
            this.txt_tel.setText(cliente.getCliTel());
            this.txt_email.setText(cliente.getCliEmail());

        } catch (NoResultException ex) {
            JOptionPane.showMessageDialog(null, "Esse é o primeiro registro",
                    "Informativo", JOptionPane.INFORMATION_MESSAGE);
        }//TRY CATCH

        Funcao.fechar(gerenciador);

    }//GEN-LAST:event_btn_anteriorActionPerformed

    private void btn_alterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_alterarActionPerformed
        int resposta = JOptionPane.showConfirmDialog(null, "Deseja alterar este Cliente ?", "Finalizando o cadastro ", JOptionPane.YES_NO_OPTION);

        if (resposta == 0) {

            gerenciador = Funcao.conectar();

            cliente.setId(Integer.parseInt(this.lbl_codigo_cli.getText()));
            cliente.setCliNome(this.txt_nome.getText());
            cliente.setCliCpf(this.txt_cpf.getText());
            cliente.setCliTel(this.txt_tel.getText());
            cliente.setCliEmail(this.txt_email.getText());

            consulta = gerenciador.createQuery("select c from Cliente c where c.id = :id");
            consulta.setParameter("id", cliente.getId());
            gerenciador.getTransaction().begin();
            gerenciador.merge(cliente);
            gerenciador.getTransaction().commit();

            JOptionPane.showMessageDialog(null, "Alterado com sucesso !");

        } else {

            this.reiniciaFormulario();

        }
    }//GEN-LAST:event_btn_alterarActionPerformed

    private void btn_proximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_proximoActionPerformed

        gerenciador = Funcao.conectar();

        try {//TRATAMENTO DE ERROS
            //Seleciona apenas o primeiro registro com o id maior que o passado
            consulta = gerenciador.createQuery("select c from Cliente c where c.id > :id");//HQL
            consulta.setParameter("id", cliente.getId()); //Compara o id do banco com o id do parâmetro
            consulta.setMaxResults(1);//Captura o primeiro registro
            cliente = (Cliente) consulta.getSingleResult();

            this.lbl_codigo_cli.setText("" + cliente.getId());
            this.txt_nome.setText(cliente.getCliNome());
            this.txt_cpf.setText(cliente.getCliCpf());
            this.txt_tel.setText(cliente.getCliTel());
            this.txt_email.setText(cliente.getCliEmail());

        } catch (NoResultException ex) {
            JOptionPane.showMessageDialog(null, "Esse é o último registro",
                    "Informativo", JOptionPane.INFORMATION_MESSAGE);
        }//TRY CATCH

        Funcao.fechar(gerenciador);
    }//GEN-LAST:event_btn_proximoActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_alterar;
    private javax.swing.JButton btn_anterior;
    private javax.swing.JButton btn_buscar_cli;
    private javax.swing.JButton btn_cancela;
    private javax.swing.JButton btn_limpar;
    private javax.swing.JButton btn_novo;
    private javax.swing.JButton btn_proximo;
    private javax.swing.JButton btn_salvar;
    private javax.swing.JLabel cli_lbl1;
    private javax.swing.JLabel cli_lbl2;
    private javax.swing.JLabel cli_lbl3;
    private javax.swing.JLabel cli_lbl4;
    private javax.swing.JLabel cli_lbl5;
    private javax.swing.JLabel lbl_cod;
    private javax.swing.JLabel lbl_codigo_cli;
    private javax.swing.JPanel painel_cad;
    private javax.swing.JPanel painel_cad2;
    private javax.swing.JFormattedTextField txt_busca;
    private javax.swing.JFormattedTextField txt_cpf;
    private javax.swing.JTextField txt_email;
    private javax.swing.JTextField txt_nome;
    private javax.swing.JFormattedTextField txt_tel;
    // End of variables declaration//GEN-END:variables

    public void reiniciaFormulario() {

        this.btn_novo.setEnabled(true);
        this.btn_alterar.setEnabled(false);
        this.btn_anterior.setEnabled(false);
        this.btn_cancela.setEnabled(false);
        this.btn_limpar.setEnabled(false);
        this.btn_proximo.setEnabled(false);
        this.btn_salvar.setEnabled(false);
        this.btn_buscar_cli.setEnabled(true);

        this.txt_cpf.setEnabled(false);
        this.txt_email.setEnabled(false);
        this.txt_nome.setEnabled(false);
        this.txt_tel.setEnabled(false);
        this.txt_busca.setEnabled(true);

        this.lbl_codigo_cli.setText("");
        this.txt_cpf.setText("");
        this.txt_nome.setText("");
        this.txt_tel.setText("");
        this.txt_email.setText("");
        this.txt_busca.setText("");
    }
}
